﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public  class OrdersProductDetailDAO
    { 
        CameraDBEntities db = new CameraDBEntities();
        public List<OrdersProductDetail> GetListAll()
        {
            return db.OrdersProductDetails.ToList();
        }
        public List<OrdersProductDetail> GetListAll_Sort()
        {
            return db.OrdersProductDetails.OrderByDescending(x => x.ordersProductDetailsId).ToList();
        }
        public List<OrdersProductDetail> GetListTop10()
        {
            return db.OrdersProductDetails.Take(10).ToList();
        }
        public OrdersProductDetail GetById(int id)
        {
            return db.OrdersProductDetails.Where(x => x.ordersProductDetailsId == id ).SingleOrDefault();
        }

        public List<OrdersProductDetail> GetListByOrderId(int id)
        {
            return db.OrdersProductDetails.Where(x=>x.ordersId == id).OrderByDescending(x => x.ordersProductDetailsId).ToList();
        }

        public bool Insert(OrdersProductDetail c)
        {
            try
            {
                db.OrdersProductDetails.Add(c);
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Edit(OrdersProductDetail ca)
        {
            try
            {
                OrdersProductDetail a = new OrdersProductDetail();
                //a = db.OrdersProductDetailes.Where(x => x.OrdersProductDetailId == ca.OrdersProductDetailId).SingleOrDefault();
                //a.OrdersProductDetailNames = ca.OrdersProductDetailNames;
                //a.OrdersProductDetailImages = ca.OrdersProductDetailImages;
                //a.OrdersProductDetailPrice = ca.OrdersProductDetailPrice;
                //a.OrdersProductDetailDetails = ca.OrdersProductDetailDetails;
                //a.OrdersProductDetailFocalOrdersProductDetailgth = ca.OrdersProductDetailFocalOrdersProductDetailgth;
                //a.OrdersProductDetailMaxaperture = ca.OrdersProductDetailMaxaperture;
                //a.OrdersProductDetailMinaperture = ca.OrdersProductDetailMinaperture;
                //a.OrdersProductDetailMinfocus = ca.OrdersProductDetailMinfocus;
                //a.OrdersProductDetailMaxmagnification = ca.OrdersProductDetailMaxmagnification;
                //a.OrdersProductDetailStatus = ca.OrdersProductDetailStatus;
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Delete(int id)
        {
            try
            {
                OrdersProductDetail a = new OrdersProductDetail();
                a = db.OrdersProductDetails.Where(x => x.ordersProductDetailsId == id).SingleOrDefault();
                db.OrdersProductDetails.Remove(a);


                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
